<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <div>
        <span @click="searchHistories.splice(0)">全部删除</span> &nbsp;
        <span @click="isDeleteShow = false">完成</span>
      </div>
      <van-icon name="delete" @click="isDeleteShow = true" />
    </van-cell>
    <van-cell
      :title="item"
      v-for="(item, index) in searchHistories"
      :key="index"
      @click="deleteHistory(index, item)"
    >
      <van-icon name="close" />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: "SearchHistory",

  props: {
    searchHistories: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      isDeleteShow: false
    };
  },

  methods: {
    deleteHistory(index, val) {
      if (this.isDeleteShow) {
        this.searchHistories.splice(index, 1);
      } else {
        this.$emit("search", val);
      }
    }
  }
};
</script>

<style scoped lang="less"></style>
